﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using acessaDB;
using Frame;
using System.Data;
using System.Configuration;
using FirebirdSql.Data.FirebirdClient;
using Estrutura;


namespace Banco
{

    public class BD_PartNumber
    {
        #region variaveis_globais

        acessaDB.conectaDBFireBird fireBird = new conectaDBFireBird();
        string conectionString = System.Configuration.ConfigurationManager.AppSettings["FireBirdConnectionLocal"];
        string usuario = string.Empty;

        #endregion

        #region construtor

        public BD_PartNumber()
        {
            if (System.Configuration.ConfigurationManager.AppSettings["ambiente"] == "PROD")
                conectionString = System.Configuration.ConfigurationManager.AppSettings["FireBirdConnectionProd"];
        }
        public BD_PartNumber(string usu_Login)
        {
            if (System.Configuration.ConfigurationManager.AppSettings["ambiente"] == "PROD")
                conectionString = System.Configuration.ConfigurationManager.AppSettings["FireBirdConnectionProd"];
            usuario = usu_Login;
        }

        #endregion

        #region metodos

        public DataSet _retorna_PartNumber(
                                                string PART_NUMBER_ID,
                                                string PNU_PART_NUMBER,
                                                string PNU_DESCRICAO_PORTUGUES,
                                                string PNU_DESCRICAO_INGLES,
                                                string PNU_ATIVO,
                                                string FABRICANTE_ID,
                                                string UME_CODIGO,
                                                string PNU_LOTE_OU_SERIE,
                                                string PNU_REPARAVEL,
                                                string PNU_ESTOCAVEL,
                                                string PNU_CONTROLA_VIDA,
                                                string PNU_AERONAUTICO,
                                                string PNU_IMPORTADO,
                                                string PNU_INSUMO,
                                                string UME_CODIGO_PESO,
                                                string PNU_PESO,
                                                string NCM_CODIGO,
                                                string PNU_PASTA_MANUAL,
                                                string PNU_OBSERVACOES,
                                                string USU_INSERT,
                                                string DATA_INSERT,
                                                string USU_UPDATE,
                                                string DATA_UPDATE,
                                                string PNU_POSSUI_LE,
                                                string PNU_CALIBRAVEL,
                                                string PNU_PATRIMONIO,
                                                string PNU_CLASSE,
                                                string PNU_FABRICACAO
                                                )
        {

            if (string.IsNullOrEmpty(PART_NUMBER_ID)) PART_NUMBER_ID = "'0'";
            if (string.IsNullOrEmpty(PNU_PART_NUMBER)) PNU_PART_NUMBER = "''";
            if (string.IsNullOrEmpty(PNU_DESCRICAO_PORTUGUES)) PNU_DESCRICAO_PORTUGUES = "''";
            if (string.IsNullOrEmpty(PNU_DESCRICAO_INGLES)) PNU_DESCRICAO_INGLES = "''";
            if (string.IsNullOrEmpty(PNU_ATIVO)) PNU_ATIVO = "''";
            if (string.IsNullOrEmpty(FABRICANTE_ID)) FABRICANTE_ID = "'0'";
            if (string.IsNullOrEmpty(UME_CODIGO)) UME_CODIGO = "''";
            if (string.IsNullOrEmpty(PNU_LOTE_OU_SERIE)) PNU_LOTE_OU_SERIE = "''";
            if (string.IsNullOrEmpty(PNU_REPARAVEL)) PNU_REPARAVEL = "''";
            if (string.IsNullOrEmpty(PNU_ESTOCAVEL)) PNU_ESTOCAVEL = "''";
            if (string.IsNullOrEmpty(PNU_CONTROLA_VIDA)) PNU_CONTROLA_VIDA = "''";
            if (string.IsNullOrEmpty(PNU_AERONAUTICO)) PNU_AERONAUTICO = "''";
            if (string.IsNullOrEmpty(PNU_IMPORTADO)) PNU_IMPORTADO = "''";
            if (string.IsNullOrEmpty(PNU_INSUMO)) PNU_INSUMO = "''";
            if (string.IsNullOrEmpty(UME_CODIGO_PESO)) UME_CODIGO_PESO = "''";
            if (string.IsNullOrEmpty(PNU_PESO)) PNU_PESO = "'0'";
            if (string.IsNullOrEmpty(NCM_CODIGO)) NCM_CODIGO = "''";
            if (string.IsNullOrEmpty(PNU_PASTA_MANUAL)) PNU_PASTA_MANUAL = "''";
            if (string.IsNullOrEmpty(PNU_OBSERVACOES)) PNU_OBSERVACOES = "''";
            if (string.IsNullOrEmpty(USU_INSERT)) USU_INSERT = "'0'";
            if (string.IsNullOrEmpty(DATA_INSERT)) DATA_INSERT = "''";
            if (string.IsNullOrEmpty(USU_UPDATE)) USU_UPDATE = "'0'";
            if (string.IsNullOrEmpty(DATA_UPDATE)) DATA_UPDATE = "''";
            if (string.IsNullOrEmpty(PNU_POSSUI_LE)) PNU_POSSUI_LE = "''";
            if (string.IsNullOrEmpty(PNU_CALIBRAVEL)) PNU_CALIBRAVEL = "''";
            if (string.IsNullOrEmpty(PNU_PATRIMONIO)) PNU_PATRIMONIO = "''";
            if (string.IsNullOrEmpty(PNU_CLASSE)) PNU_CLASSE = "''";
            if (string.IsNullOrEmpty(PNU_FABRICACAO)) PNU_FABRICACAO = "''";

            string sql = "SELECT " +
                                  "PN_CADASTRO.PART_NUMBER_ID, " +
                                  "PN_CADASTRO.PNU_PART_NUMBER, " +
                                  "PN_CADASTRO.PNU_DESCRICAO_PORTUGUES, " +
                                  "PN_CADASTRO.PNU_DESCRICAO_INGLES, " +
                                  "PN_CADASTRO.PNU_ATIVO, " +
                                  "PN_CADASTRO.FABRICANTE_ID, " +
                                  "PN_CADASTRO.UME_CODIGO, " +
                                  "PN_CADASTRO.PNU_LOTE_OU_SERIE, " +
                                  "PN_CADASTRO.PNU_REPARAVEL, " +
                                  "PN_CADASTRO.PNU_ESTOCAVEL, " +
                                  "PN_CADASTRO.PNU_CONTROLA_VIDA, " +
                                  "PN_CADASTRO.PNU_AERONAUTICO, " +
                                  "PN_CADASTRO.PNU_IMPORTADO, " +
                                  "PN_CADASTRO.PNU_INSUMO, " +
                                  "PN_CADASTRO.UME_CODIGO_PESO, " +
                                  "PN_CADASTRO.PNU_PESO, " +
                                  "PN_CADASTRO.NCM_CODIGO, " +
                                  "PN_CADASTRO.PNU_PASTA_MANUAL, " +
                                  "PN_CADASTRO.PNU_OBSERVACOES, " +
                                  "PN_CADASTRO.USU_INSERT, " +
                                  "PN_CADASTRO.DATA_INSERT, " +
                                  "PN_CADASTRO.USU_UPDATE, " +
                                  "PN_CADASTRO.DATA_UPDATE, " +
                                  "PN_CADASTRO.PNU_POSSUI_LE, " +
                                  "PN_CADASTRO.PNU_CALIBRAVEL, " +
                                  "PN_CADASTRO.PNU_PATRIMONIO, " +
                                  "PN_CADASTRO.PNU_CLASSE, " +
                                  "PN_CADASTRO.PNU_FABRICACAO " +
                            "FROM PN_CADASTRO " +
                            "LEFT JOIN ENTIDADE ON ENTIDADE.ENTIDADE_ID = PN_CADASTRO.ENTIDADE_ID " +
                            "LEFT JOIN NCM ON NCM.NCM_ID = PN_CADASTRO.NCM_ID " +
                            "LEFT JOIN UNIDADE_MEDIDA ON UNIDADE_MEDIDA.UNIDADE_MEDIDA_ID = PN_CADASTRO.UNIDADE_MEDIDA_ID " +
                            "LEFT JOIN UNIDADE_MEDIDA ON UNIDADE_MEDIDA.UNIDADE_MEDIDA_ID = PN_CADASTRO.UNIDADE_MEDIDA_ID " +
                            "LEFT JOIN USUARIO ON USUARIO.USUARIO_ID = PN_CADASTRO.USUARIO_ID " +
                            "LEFT JOIN USUARIO ON USUARIO.USUARIO_ID = PN_CADASTRO.USUARIO_ID " +
                            "WHERE " +
                            "      (PN_CADASTRO.PART_NUMBER_ID                  = " + PART_NUMBER_ID + "  OR " + PART_NUMBER_ID + " = '0') AND " +
                            "      (PN_CADASTRO.PNU_PART_NUMBER                 = " + PNU_PART_NUMBER + "  OR " + PNU_PART_NUMBER + " = '') AND " +
                            "      (PN_CADASTRO.PNU_DESCRICAO_PORTUGUES         = " + PNU_DESCRICAO_PORTUGUES + "  OR " + PNU_DESCRICAO_PORTUGUES + " = '') AND " +
                            "      (PN_CADASTRO.PNU_DESCRICAO_INGLES            = " + PNU_DESCRICAO_INGLES + "  OR " + PNU_DESCRICAO_INGLES + " = '') AND " +
                            "      (PN_CADASTRO.PNU_ATIVO                       = " + PNU_ATIVO + "  OR " + PNU_ATIVO + " = '') AND " +
                            "      (PN_CADASTRO.FABRICANTE_ID                   = " + FABRICANTE_ID + "  OR " + FABRICANTE_ID + " = '0') AND " +
                            "      (PN_CADASTRO.UME_CODIGO                      = " + UME_CODIGO + "  OR " + UME_CODIGO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_LOTE_OU_SERIE               = " + PNU_LOTE_OU_SERIE + "  OR " + PNU_LOTE_OU_SERIE + " = '') AND " +
                            "      (PN_CADASTRO.PNU_REPARAVEL                   = " + PNU_REPARAVEL + "  OR " + PNU_REPARAVEL + " = '') AND " +
                            "      (PN_CADASTRO.PNU_ESTOCAVEL                   = " + PNU_ESTOCAVEL + "  OR " + PNU_ESTOCAVEL + " = '') AND " +
                            "      (PN_CADASTRO.PNU_CONTROLA_VIDA               = " + PNU_CONTROLA_VIDA + "  OR " + PNU_CONTROLA_VIDA + " = '') AND " +
                            "      (PN_CADASTRO.PNU_AERONAUTICO                 = " + PNU_AERONAUTICO + "  OR " + PNU_AERONAUTICO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_IMPORTADO                   = " + PNU_IMPORTADO + "  OR " + PNU_IMPORTADO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_INSUMO                      = " + PNU_INSUMO + "  OR " + PNU_INSUMO + " = '') AND " +
                            "      (PN_CADASTRO.UME_CODIGO_PESO                 = " + UME_CODIGO_PESO + "  OR " + UME_CODIGO_PESO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_PESO                        = " + PNU_PESO + "  OR " + PNU_PESO + " = '0') AND " +
                            "      (PN_CADASTRO.NCM_CODIGO                      = " + NCM_CODIGO + "  OR " + NCM_CODIGO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_PASTA_MANUAL                = " + PNU_PASTA_MANUAL + "  OR " + PNU_PASTA_MANUAL + " = '') AND " +
                            "      (PN_CADASTRO.PNU_OBSERVACOES                 = " + PNU_OBSERVACOES + "  OR " + PNU_OBSERVACOES + " = '') AND " +
                            "      (PN_CADASTRO.USU_INSERT                      = " + USU_INSERT + "  OR " + USU_INSERT + " = '0') AND " +
                            "      (PN_CADASTRO.DATA_INSERT                     = " + DATA_INSERT + "  OR " + DATA_INSERT + " = '') AND " +
                            "      (PN_CADASTRO.USU_UPDATE                      = " + USU_UPDATE + "  OR " + USU_UPDATE + " = '0') AND " +
                            "      (PN_CADASTRO.DATA_UPDATE                     = " + DATA_UPDATE + "  OR " + DATA_UPDATE + " = '') AND " +
                            "      (PN_CADASTRO.PNU_POSSUI_LE                   = " + PNU_POSSUI_LE + "  OR " + PNU_POSSUI_LE + " = '') AND " +
                            "      (PN_CADASTRO.PNU_CALIBRAVEL                  = " + PNU_CALIBRAVEL + "  OR " + PNU_CALIBRAVEL + " = '') AND " +
                            "      (PN_CADASTRO.PNU_PATRIMONIO                  = " + PNU_PATRIMONIO + "  OR " + PNU_PATRIMONIO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_CLASSE                      = " + PNU_CLASSE + "  OR " + PNU_CLASSE + " = '') AND " +
                            "      (PN_CADASTRO.PNU_FABRICACAO                  = " + PNU_FABRICACAO + "  OR " + PNU_FABRICACAO + " = '') ";

            DataSet dsRetorno = fireBird.retornaDataSet(sql, conectionString);
            return dsRetorno;

        }


        public List<ES_PartNumber> _obter_PartNumber(
                                                string PART_NUMBER_ID,
                                                string PNU_PART_NUMBER,
                                                string PNU_DESCRICAO_PORTUGUES,
                                                string PNU_DESCRICAO_INGLES,
                                                string PNU_ATIVO,
                                                string FABRICANTE_ID,
                                                string UME_CODIGO,
                                                string PNU_LOTE_OU_SERIE,
                                                string PNU_REPARAVEL,
                                                string PNU_ESTOCAVEL,
                                                string PNU_CONTROLA_VIDA,
                                                string PNU_AERONAUTICO,
                                                string PNU_IMPORTADO,
                                                string PNU_INSUMO,
                                                string UME_CODIGO_PESO,
                                                string PNU_PESO,
                                                string NCM_CODIGO,
                                                string PNU_PASTA_MANUAL,
                                                string PNU_OBSERVACOES,
                                                string USU_INSERT,
                                                string DATA_INSERT,
                                                string USU_UPDATE,
                                                string DATA_UPDATE,
                                                string PNU_POSSUI_LE,
                                                string PNU_CALIBRAVEL,
                                                string PNU_PATRIMONIO,
                                                string PNU_CLASSE,
                                                string PNU_FABRICACAO,
                                                string ORDER_BY_CLAUSE
                                                )
        {

            if (string.IsNullOrEmpty(PART_NUMBER_ID)) PART_NUMBER_ID = "'0'";
            if (string.IsNullOrEmpty(PNU_PART_NUMBER)) PNU_PART_NUMBER = "''"; else PNU_PART_NUMBER = Util.retonarAspas(PNU_PART_NUMBER+"%");
            if (string.IsNullOrEmpty(PNU_DESCRICAO_PORTUGUES)) PNU_DESCRICAO_PORTUGUES = "''"; else PNU_DESCRICAO_PORTUGUES = Util.retonarAspas(PNU_DESCRICAO_PORTUGUES + "%");
            if (string.IsNullOrEmpty(PNU_DESCRICAO_INGLES)) PNU_DESCRICAO_INGLES = "''"; else PNU_DESCRICAO_INGLES = Util.retonarAspas(PNU_DESCRICAO_INGLES + "%");
            if (string.IsNullOrEmpty(PNU_ATIVO)) PNU_ATIVO = "''";
            if (string.IsNullOrEmpty(FABRICANTE_ID)) FABRICANTE_ID = "'0'";
            if (string.IsNullOrEmpty(UME_CODIGO)) UME_CODIGO = "''";
            if (string.IsNullOrEmpty(PNU_LOTE_OU_SERIE)) PNU_LOTE_OU_SERIE = "''";
            if (string.IsNullOrEmpty(PNU_REPARAVEL)) PNU_REPARAVEL = "''";
            if (string.IsNullOrEmpty(PNU_ESTOCAVEL)) PNU_ESTOCAVEL = "''";
            if (string.IsNullOrEmpty(PNU_CONTROLA_VIDA)) PNU_CONTROLA_VIDA = "''";
            if (string.IsNullOrEmpty(PNU_AERONAUTICO)) PNU_AERONAUTICO = "''";
            if (string.IsNullOrEmpty(PNU_IMPORTADO)) PNU_IMPORTADO = "''";
            if (string.IsNullOrEmpty(PNU_INSUMO)) PNU_INSUMO = "''";
            if (string.IsNullOrEmpty(UME_CODIGO_PESO)) UME_CODIGO_PESO = "''";
            if (string.IsNullOrEmpty(PNU_PESO)) PNU_PESO = "'0'";
            if (string.IsNullOrEmpty(NCM_CODIGO)) NCM_CODIGO = "''";
            if (string.IsNullOrEmpty(PNU_PASTA_MANUAL)) PNU_PASTA_MANUAL = "''";
            if (string.IsNullOrEmpty(PNU_OBSERVACOES)) PNU_OBSERVACOES = "''";
            if (string.IsNullOrEmpty(USU_INSERT)) USU_INSERT = "'0'";
            if (string.IsNullOrEmpty(DATA_INSERT)) DATA_INSERT = "''";
            if (string.IsNullOrEmpty(USU_UPDATE)) USU_UPDATE = "'0'";
            if (string.IsNullOrEmpty(DATA_UPDATE)) DATA_UPDATE = "''";
            if (string.IsNullOrEmpty(PNU_POSSUI_LE)) PNU_POSSUI_LE = "''";
            if (string.IsNullOrEmpty(PNU_CALIBRAVEL)) PNU_CALIBRAVEL = "''";
            if (string.IsNullOrEmpty(PNU_PATRIMONIO)) PNU_PATRIMONIO = "''";
            if (string.IsNullOrEmpty(PNU_CLASSE)) PNU_CLASSE = "''";
            if (string.IsNullOrEmpty(PNU_FABRICACAO)) PNU_FABRICACAO = "''";
            if (string.IsNullOrEmpty(ORDER_BY_CLAUSE)) ORDER_BY_CLAUSE = "PN_CADASTRO.PART_NUMBER_ID DESC";

            string sql = "SELECT " +
                                  "PN_CADASTRO.PART_NUMBER_ID, " +
                                  "PN_CADASTRO.PNU_PART_NUMBER, " +
                                  "CASE "+
                                  "      WHEN PN_CADASTRO.PNU_DESCRICAO_INGLES IS NOT NULL THEN PN_CADASTRO.PNU_DESCRICAO_INGLES "+
                                  "      ELSE PN_CADASTRO.PNU_DESCRICAO_PORTUGUES END  PNU_DESCRICAO, "+
                                  "PN_CADASTRO.PNU_DESCRICAO_PORTUGUES, " +
                                  "PN_CADASTRO.PNU_DESCRICAO_INGLES, " +
                                  "PN_CADASTRO.PNU_ATIVO, " +
                                  "PN_CADASTRO.FABRICANTE_ID, " +
                                  "ENTIDADE.ENT_RAZAO_SOCIAL, "+
                                  "PN_CADASTRO.UME_CODIGO, " +
                                  "PN_CADASTRO.PNU_LOTE_OU_SERIE, " +
                                  "PN_CADASTRO.PNU_REPARAVEL, " +
                                  "PN_CADASTRO.PNU_ESTOCAVEL, " +
                                  "PN_CADASTRO.PNU_CONTROLA_VIDA, " +
                                  "PN_CADASTRO.PNU_AERONAUTICO, " +
                                  "PN_CADASTRO.PNU_IMPORTADO, " +
                                  "PN_CADASTRO.PNU_INSUMO, " +
                                  "PN_CADASTRO.UME_CODIGO_PESO, " +
                                  "PN_CADASTRO.PNU_PESO, " +
                                  "PN_CADASTRO.NCM_CODIGO, " +
                                  "PN_CADASTRO.PNU_PASTA_MANUAL, " +
                                  "PN_CADASTRO.PNU_OBSERVACOES, " +
                                  "PN_CADASTRO.USU_INSERT, " +
                                  "PN_CADASTRO.DATA_INSERT, " +
                                  "PN_CADASTRO.USU_UPDATE, " +
                                  "PN_CADASTRO.DATA_UPDATE, " +
                                  "PN_CADASTRO.PNU_POSSUI_LE, " +
                                  "PN_CADASTRO.PNU_CALIBRAVEL, " +
                                  "PN_CADASTRO.PNU_PATRIMONIO, " +
                                  "PN_CADASTRO.PNU_CLASSE, " +
                                  "PN_CADASTRO.PNU_FABRICACAO " +
                            "FROM PN_CADASTRO " +
                            "LEFT JOIN ENTIDADE ON ENTIDADE.ENTIDADE_ID = PN_CADASTRO.FABRICANTE_ID " +                            
                            "WHERE " +
                            "      (PN_CADASTRO.PART_NUMBER_ID                  = " + PART_NUMBER_ID + "  OR " + PART_NUMBER_ID + " = '0') AND " +
                            "      (PN_CADASTRO.PNU_PART_NUMBER                 LIKE " + PNU_PART_NUMBER + "  OR " + PNU_PART_NUMBER + " = '') AND " +
                            "      (PN_CADASTRO.PNU_DESCRICAO_PORTUGUES         LIKE " + PNU_DESCRICAO_PORTUGUES + "  OR " + PNU_DESCRICAO_PORTUGUES + " = '') AND " +
                            "      (PN_CADASTRO.PNU_DESCRICAO_INGLES            LIKE " + PNU_DESCRICAO_INGLES + "  OR " + PNU_DESCRICAO_INGLES + " = '') AND " +
                            "      (PN_CADASTRO.PNU_ATIVO                       = " + PNU_ATIVO + "  OR " + PNU_ATIVO + " = '') AND " +
                            "      (PN_CADASTRO.FABRICANTE_ID                   = " + FABRICANTE_ID + "  OR " + FABRICANTE_ID + " = '0') AND " +
                            /*"      (PN_CADASTRO.UME_CODIGO                      = " + UME_CODIGO + "  OR " + UME_CODIGO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_LOTE_OU_SERIE               = " + PNU_LOTE_OU_SERIE + "  OR " + PNU_LOTE_OU_SERIE + " = '') AND " +
                            "      (PN_CADASTRO.PNU_REPARAVEL                   = " + PNU_REPARAVEL + "  OR " + PNU_REPARAVEL + " = '') AND " +
                            "      (PN_CADASTRO.PNU_ESTOCAVEL                   = " + PNU_ESTOCAVEL + "  OR " + PNU_ESTOCAVEL + " = '') AND " +
                            "      (PN_CADASTRO.PNU_CONTROLA_VIDA               = " + PNU_CONTROLA_VIDA + "  OR " + PNU_CONTROLA_VIDA + " = '') AND " +
                            "      (PN_CADASTRO.PNU_AERONAUTICO                 = " + PNU_AERONAUTICO + "  OR " + PNU_AERONAUTICO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_IMPORTADO                   = " + PNU_IMPORTADO + "  OR " + PNU_IMPORTADO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_INSUMO                      = " + PNU_INSUMO + "  OR " + PNU_INSUMO + " = '') AND " +
                            "      (PN_CADASTRO.UME_CODIGO_PESO                 = " + UME_CODIGO_PESO + "  OR " + UME_CODIGO_PESO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_PESO                        = " + PNU_PESO + "  OR " + PNU_PESO + " = '0') AND " +
                            "      (PN_CADASTRO.NCM_CODIGO                      = " + NCM_CODIGO + "  OR " + NCM_CODIGO + " = '') AND " +
                            "      (PN_CADASTRO.PNU_PASTA_MANUAL                = " + PNU_PASTA_MANUAL + "  OR " + PNU_PASTA_MANUAL + " = '') AND " +
                            "      (PN_CADASTRO.PNU_OBSERVACOES                 = " + PNU_OBSERVACOES + "  OR " + PNU_OBSERVACOES + " = '') AND " +                            
                            "      (PN_CADASTRO.PNU_POSSUI_LE                   = " + PNU_POSSUI_LE + "  OR " + PNU_POSSUI_LE + " = '') AND " +
                            "      (PN_CADASTRO.PNU_CALIBRAVEL                  = " + PNU_CALIBRAVEL + "  OR " + PNU_CALIBRAVEL + " = '') AND " +
                            "      (PN_CADASTRO.PNU_PATRIMONIO                  = " + PNU_PATRIMONIO + "  OR " + PNU_PATRIMONIO + " = '') AND " +*/
                            "      (PN_CADASTRO.PNU_FABRICACAO                  = " + PNU_FABRICACAO + "  OR " + PNU_FABRICACAO + " = '') "+
                            " ORDER BY " + ORDER_BY_CLAUSE;

            List<ES_PartNumber> lista = new List<ES_PartNumber>();
            FbConnection fbConexao = new FbConnection(conectionString);
            FbDataReader dr = fireBird.retornaDataReader(sql, conectionString, fbConexao);
            try
            {
                while (dr.Read())
                {
                    ES_PartNumber item = new ES_PartNumber();
                    item.PART_NUMBER_ID = dr["PART_NUMBER_ID"].ToString();
                    item.PNU_PART_NUMBER = dr["PNU_PART_NUMBER"].ToString();
                    item.PNU_DESCRICAO = dr["PNU_DESCRICAO"].ToString();
                    item.PNU_DESCRICAO_PORTUGUES = dr["PNU_DESCRICAO_PORTUGUES"].ToString();
                    item.PNU_DESCRICAO_INGLES = dr["PNU_DESCRICAO_INGLES"].ToString();
                    if (dr["PNU_ATIVO"].ToString() == "S")
                        item.PNU_ATIVO = true;
                    else
                        item.PNU_ATIVO = false;
                    item.FABRICANTE_ID = dr["FABRICANTE_ID"].ToString();
                    item.ENT_RAZAO_SOCIAL = dr["ENT_RAZAO_SOCIAL"].ToString();
                    item.UME_CODIGO = dr["UME_CODIGO"].ToString();
                    item.PNU_LOTE_OU_SERIE = dr["PNU_LOTE_OU_SERIE"].ToString();
                    item.PNU_REPARAVEL = dr["PNU_REPARAVEL"].ToString();
                    item.PNU_ESTOCAVEL = dr["PNU_ESTOCAVEL"].ToString();
                    item.PNU_CONTROLA_VIDA = dr["PNU_CONTROLA_VIDA"].ToString();
                    item.PNU_AERONAUTICO = dr["PNU_AERONAUTICO"].ToString();
                    item.PNU_IMPORTADO = dr["PNU_IMPORTADO"].ToString();
                    item.PNU_INSUMO = dr["PNU_INSUMO"].ToString();
                    item.UME_CODIGO_PESO = dr["UME_CODIGO_PESO"].ToString();
                    item.PNU_PESO = dr["PNU_PESO"].ToString();
                    item.NCM_CODIGO = dr["NCM_CODIGO"].ToString();
                    item.PNU_PASTA_MANUAL = dr["PNU_PASTA_MANUAL"].ToString();
                    item.PNU_OBSERVACOES = dr["PNU_OBSERVACOES"].ToString();
                    item.USU_INSERT = dr["USU_INSERT"].ToString();
                    item.DATA_INSERT = dr["DATA_INSERT"].ToString();
                    item.USU_UPDATE = dr["USU_UPDATE"].ToString();
                    item.DATA_UPDATE = dr["DATA_UPDATE"].ToString();
                    item.PNU_POSSUI_LE = dr["PNU_POSSUI_LE"].ToString();
                    item.PNU_CALIBRAVEL = dr["PNU_CALIBRAVEL"].ToString();
                    item.PNU_PATRIMONIO = dr["PNU_PATRIMONIO"].ToString();
                    item.PNU_CLASSE = dr["PNU_CLASSE"].ToString();
                    item.PNU_FABRICACAO = dr["PNU_FABRICACAO"].ToString();
                    lista.Add(item);

                }
                return lista;
            }
            finally
            {
                fireBird.fecharConexao(fbConexao);
            }
        }


        public ES_PartNumber _obter_PartNumber_by_id(
                                                string PART_NUMBER_ID,
                                                string PNU_PART_NUMBER = "")
        {

            if (string.IsNullOrEmpty(PART_NUMBER_ID)) PART_NUMBER_ID = "0";
            if (string.IsNullOrEmpty(PNU_PART_NUMBER)) PNU_PART_NUMBER = "''"; else PNU_PART_NUMBER = Util.retonarAspas(PNU_PART_NUMBER);

            string sql = "SELECT " +
                                  "PN_CADASTRO.PART_NUMBER_ID, " +
                                  "PN_CADASTRO.PNU_PART_NUMBER, " +
                                  "PN_CADASTRO.PNU_DESCRICAO_PORTUGUES, " +
                                  "PN_CADASTRO.PNU_DESCRICAO_INGLES, " +
                                  "PN_CADASTRO.PNU_ATIVO, " +
                                  "PN_CADASTRO.FABRICANTE_ID, " +
                                  "PN_CADASTRO.UME_CODIGO, " +
                                  "PN_CADASTRO.PNU_LOTE_OU_SERIE, " +
                                  "PN_CADASTRO.PNU_REPARAVEL, " +
                                  "PN_CADASTRO.PNU_ESTOCAVEL, " +
                                  "PN_CADASTRO.PNU_CONTROLA_VIDA, " +
                                  "PN_CADASTRO.PNU_AERONAUTICO, " +
                                  "PN_CADASTRO.PNU_IMPORTADO, " +
                                  "PN_CADASTRO.PNU_INSUMO, " +
                                  "PN_CADASTRO.UME_CODIGO_PESO, " +
                                  "PN_CADASTRO.PNU_PESO, " +
                                  "PN_CADASTRO.NCM_CODIGO, " +
                                  "PN_CADASTRO.PNU_PASTA_MANUAL, " +
                                  "CAST(PN_CADASTRO.PNU_OBSERVACOES AS VARCHAR(2000)) PNU_OBSERVACOES, " +
                                  "PN_CADASTRO.USU_INSERT, " +
                                  "PN_CADASTRO.DATA_INSERT, " +
                                  "PN_CADASTRO.USU_UPDATE, " +
                                  "PN_CADASTRO.DATA_UPDATE, " +
                                  "PN_CADASTRO.PNU_POSSUI_LE, " +
                                  "PN_CADASTRO.PNU_CALIBRAVEL, " +
                                  "PN_CADASTRO.PNU_PATRIMONIO, " +
                                  "PN_CADASTRO.PNU_CLASSE, " +
                                  "PN_CADASTRO.PNU_FABRICACAO, " +
                                  "PN_CADASTRO.PNU_EQPOBRIG_DT_FABR, " +
                                  "PN_CADASTRO.PNU_EQPOBRIG_DT_INSTAL, " +
                                  "PN_CADASTRO.PNU_EQPALTERA_PN, " +
                                  "PN_CADASTRO.PNU_EQPALTERA_SN, " +
                                  "(SELECT MODELO_ID FROM MODELO_PN M WHERE M.PART_NUMBER_ID = PN_CADASTRO.PART_NUMBER_ID) MODELO_ID " +
                            "FROM PN_CADASTRO " +
                            "LEFT JOIN ENTIDADE ON ENTIDADE.ENTIDADE_ID = PN_CADASTRO.FABRICANTE_ID " +                            
                            "WHERE " +
                            "      (PN_CADASTRO.PART_NUMBER_ID = " + PART_NUMBER_ID + "  OR " + PART_NUMBER_ID + " = '0') "+
                            "      AND (PN_CADASTRO.PNU_PART_NUMBER = " + PNU_PART_NUMBER + "  OR " + PNU_PART_NUMBER + " = '') ";

            ES_PartNumber item = new ES_PartNumber();
            FbConnection fbConexao = new FbConnection(conectionString);
            FbDataReader dr = fireBird.retornaDataReader(sql, conectionString, fbConexao);
            try
            {
                while (dr.Read())
                {
                    item.PART_NUMBER_ID = dr["PART_NUMBER_ID"].ToString();
                    item.PNU_PART_NUMBER = dr["PNU_PART_NUMBER"].ToString();
                    item.PNU_DESCRICAO_PORTUGUES = dr["PNU_DESCRICAO_PORTUGUES"].ToString();
                    item.PNU_DESCRICAO_INGLES = dr["PNU_DESCRICAO_INGLES"].ToString();
                    if (!string.IsNullOrEmpty(item.PNU_DESCRICAO_INGLES))
                        item.PNU_DESCRICAO = item.PNU_DESCRICAO_INGLES;
                    else
                        item.PNU_DESCRICAO = item.PNU_DESCRICAO_PORTUGUES;
                    if (dr["PNU_ATIVO"].ToString() == "S")
                        item.PNU_ATIVO = true;
                    else
                        item.PNU_ATIVO = false;
                    item.FABRICANTE_ID = dr["FABRICANTE_ID"].ToString();
                    item.UME_CODIGO = dr["UME_CODIGO"].ToString();
                    item.PNU_LOTE_OU_SERIE = dr["PNU_LOTE_OU_SERIE"].ToString();
                    item.PNU_REPARAVEL = dr["PNU_REPARAVEL"].ToString();
                    item.PNU_ESTOCAVEL = dr["PNU_ESTOCAVEL"].ToString();
                    item.PNU_CONTROLA_VIDA = dr["PNU_CONTROLA_VIDA"].ToString();
                    item.PNU_AERONAUTICO = dr["PNU_AERONAUTICO"].ToString();
                    item.PNU_IMPORTADO = dr["PNU_IMPORTADO"].ToString();
                    item.PNU_INSUMO = dr["PNU_INSUMO"].ToString();
                    item.UME_CODIGO_PESO = dr["UME_CODIGO_PESO"].ToString();
                    item.PNU_PESO = dr["PNU_PESO"].ToString();
                    item.NCM_CODIGO = dr["NCM_CODIGO"].ToString();
                    item.PNU_PASTA_MANUAL = dr["PNU_PASTA_MANUAL"].ToString();
                    item.PNU_OBSERVACOES = dr["PNU_OBSERVACOES"].ToString();
                    item.USU_INSERT = dr["USU_INSERT"].ToString();
                    item.DATA_INSERT = dr["DATA_INSERT"].ToString();
                    item.USU_UPDATE = dr["USU_UPDATE"].ToString();
                    item.DATA_UPDATE = dr["DATA_UPDATE"].ToString();
                    item.PNU_POSSUI_LE = dr["PNU_POSSUI_LE"].ToString();
                    item.PNU_CALIBRAVEL = dr["PNU_CALIBRAVEL"].ToString();
                    item.PNU_PATRIMONIO = dr["PNU_PATRIMONIO"].ToString();
                    item.PNU_CLASSE = dr["PNU_CLASSE"].ToString();
                    item.PNU_FABRICACAO = dr["PNU_FABRICACAO"].ToString();
                    item.PNU_EQPOBRIG_DT_FABR = dr["PNU_EQPOBRIG_DT_FABR"].ToString();
                    item.PNU_EQPOBRIG_DT_INSTAL = dr["PNU_EQPOBRIG_DT_INSTAL"].ToString();
                    item.PNU_EQPALTERA_PN = dr["PNU_EQPALTERA_PN"].ToString();
                    item.PNU_EQPALTERA_SN = dr["PNU_EQPALTERA_SN"].ToString();
                    item.MODELO_ID = dr["MODELO_ID"].ToString();
                }
                return item;
            }
            finally
            {
                fireBird.fecharConexao(fbConexao);
            }
        }


        public List<ES_PartNumber_Instalados> _obter_PartNumbers_instalados(string PART_NUMBER_ID)
        {

            if (string.IsNullOrEmpty(PART_NUMBER_ID)) PART_NUMBER_ID = "0";

            string sql = "SELECT EQUIPAMENTO_ID, "+
                         "       EQUIPAMENTO_PAI_ID, "+
                         "       CELULA, "+
                         "       EQU_DESCRICAO, "+
                         "       EQU_SERIAL_NUMBER, "+
                         "       DATA_INSTALACAO, "+
                         "       CTM_EVENTO_ID " +
                         "FROM FN_PARTNUMBER_INSTALDOS("+PART_NUMBER_ID+")";

            List<ES_PartNumber_Instalados> lista = new List<ES_PartNumber_Instalados>();
            FbConnection fbConexao = new FbConnection(conectionString);
            FbDataReader dr = fireBird.retornaDataReader(sql, conectionString, fbConexao);
            try
            {
                while (dr.Read())
                {
                    ES_PartNumber_Instalados item = new ES_PartNumber_Instalados();
                    item.EQUIPAMENTO_ID = dr["EQUIPAMENTO_ID"].ToString();
                    item.EQUIPAMENTO_PAI_ID = dr["EQUIPAMENTO_PAI_ID"].ToString();
                    item.CELULA = dr["CELULA"].ToString();
                    item.EQU_DESCRICAO = dr["EQU_DESCRICAO"].ToString();
                    item.EQU_SERIAL_NUMBER = dr["EQU_SERIAL_NUMBER"].ToString();
                    item.DATA_INSTALACAO = Util.formataData(dr["DATA_INSTALACAO"].ToString(), "dd/MM/yyyy");
                    item.CTM_EVENTO_ID = dr["CTM_EVENTO_ID"].ToString();
                    lista.Add(item);
                }

                return lista;
            }
            finally
            {
                fireBird.fecharConexao(fbConexao);
            }
        }


        public void _inserir_PartNumber(
                                                string PART_NUMBER_ID,
                                                string PNU_PART_NUMBER,
                                                string PNU_DESCRICAO_PORTUGUES,
                                                string PNU_DESCRICAO_INGLES,
                                                string PNU_ATIVO,
                                                string FABRICANTE_ID,
                                                string UME_CODIGO,
                                                string PNU_LOTE_OU_SERIE,
                                                string PNU_REPARAVEL,
                                                string PNU_ESTOCAVEL,
                                                string PNU_CONTROLA_VIDA,
                                                string PNU_AERONAUTICO,
                                                string PNU_IMPORTADO,
                                                string PNU_INSUMO,
                                                string UME_CODIGO_PESO,
                                                string PNU_PESO,
                                                string NCM_CODIGO,
                                                string PNU_PASTA_MANUAL,
                                                string PNU_OBSERVACOES,
                                                string USU_INSERT,
                                                string DATA_INSERT,
                                                string USU_UPDATE,
                                                string DATA_UPDATE,
                                                string PNU_POSSUI_LE,
                                                string PNU_CALIBRAVEL,
                                                string PNU_PATRIMONIO,
                                                string PNU_CLASSE,
                                                string PNU_FABRICACAO,
                                                string PNU_EQPOBRIG_DT_FABR,
                                                string PNU_EQPOBRIG_DT_INSTAL,
                                                string PNU_EQPALTERA_PN,
                                                string PNU_EQPALTERA_SN
                                                )
        {

            string sql = " INSERT INTO PN_CADASTRO " +
                         "      ( " +
                         //"          PART_NUMBER_ID                 , " +
                         "          PNU_PART_NUMBER                , " +
                         "          PNU_DESCRICAO_PORTUGUES        , " +
                         "          PNU_DESCRICAO_INGLES           , " +
                         "          PNU_ATIVO                      , " +
                         "          FABRICANTE_ID                  , " +
                         "          UME_CODIGO                     , " +
                         "          PNU_LOTE_OU_SERIE              , " +
                         "          PNU_REPARAVEL                  , " +
                         "          PNU_ESTOCAVEL                  , " +
                         "          PNU_CONTROLA_VIDA              , " +
                         "          PNU_AERONAUTICO                , " +
                         "          PNU_IMPORTADO                  , " +
                         "          PNU_INSUMO                     , " +
                         "          UME_CODIGO_PESO                , " +
                         "          PNU_PESO                       , " +
                         "          NCM_CODIGO                     , " +
                         "          PNU_PASTA_MANUAL               , " +
                         "          PNU_OBSERVACOES                , " +
                         "          USU_INSERT                     , " +
                         "          DATA_INSERT                    , " +
                         "          USU_UPDATE                     , " +
                         "          DATA_UPDATE                    , " +
                         "          PNU_POSSUI_LE                  , " +
                         "          PNU_CALIBRAVEL                 , " +
                         "          PNU_PATRIMONIO                 , " +
                         "          PNU_CLASSE                     , " +
                         "          PNU_FABRICACAO                 , " +
                         "          PNU_EQPOBRIG_DT_FABR           , " +
                         "          PNU_EQPOBRIG_DT_INSTAL         , " +           
                         "          PNU_EQPALTERA_PN               , " +
                         "          PNU_EQPALTERA_SN                 " +
                 "      )" +
                 "  VALUES " +
                 "      ( " +
                              //PART_NUMBER_ID + ", " +
                              Util.retonarAspas(PNU_PART_NUMBER, true) + ", " +
                              Util.retonarAspas(PNU_DESCRICAO_PORTUGUES, true) + ", " +
                              Util.retonarAspas(PNU_DESCRICAO_INGLES, true) + ", " +
                              Util.retonarAspas(PNU_ATIVO, true) + ", " +
                              Util.retonarAspas(FABRICANTE_ID, true) + ", " +
                              Util.retonarAspas(UME_CODIGO, true) + ", " +
                              Util.retonarAspas(PNU_LOTE_OU_SERIE, true) + ", " +
                              Util.retonarAspas(PNU_REPARAVEL, true) + ", " +
                              Util.retonarAspas(PNU_ESTOCAVEL, true) + ", " +
                              Util.retonarAspas(PNU_CONTROLA_VIDA, true) + ", " +
                              Util.retonarAspas(PNU_AERONAUTICO, true) + ", " +
                              Util.retonarAspas(PNU_IMPORTADO, true) + ", " +
                              Util.retonarAspas(PNU_INSUMO, true) + ", " +
                              Util.retonarAspas(UME_CODIGO_PESO, true) + ", " +
                              Util.retonarAspas(PNU_PESO, true) + ", " +
                              Util.retonarAspas(NCM_CODIGO, true) + ", " +
                              Util.retonarAspas(PNU_PASTA_MANUAL, true) + ", " +
                              Util.retonarAspas(PNU_OBSERVACOES, true) + ", " +
                              Util.retonarAspas(USU_INSERT, true) + ", " +
                              Util.retonarAspas(DATA_INSERT, true) + ", " +
                              Util.retonarAspas(USU_UPDATE, true) + ", " +
                              Util.retonarAspas(DATA_UPDATE, true) + ", " +
                              Util.retonarAspas(PNU_POSSUI_LE, true) + ", " +
                              Util.retonarAspas(PNU_CALIBRAVEL, true) + ", " +
                              Util.retonarAspas(PNU_PATRIMONIO, true) + ", " +
                              Util.retonarAspas(PNU_CLASSE, true) + ", " +
                              Util.retonarAspas(PNU_FABRICACAO, true) +", " +
                              Util.retonarAspas(PNU_EQPOBRIG_DT_FABR, true) + ", " +
                              Util.retonarAspas(PNU_EQPOBRIG_DT_INSTAL, true) + ", " +
                              Util.retonarAspas(PNU_EQPALTERA_PN, true) + ", " +
                              Util.retonarAspas(PNU_EQPALTERA_SN, true) +
                 "      )";
            try
            {
                fireBird._ExecutarComandoRetornandoID(sql, conectionString, false, usuario);
            }
            catch
            { }
        }



        public void _atualizar_PartNumber(
                                                string PART_NUMBER_ID,
                                                string PNU_PART_NUMBER,
                                                string PNU_DESCRICAO_PORTUGUES,
                                                string PNU_DESCRICAO_INGLES,
                                                string PNU_ATIVO,
                                                string FABRICANTE_ID,
                                                string UME_CODIGO,
                                                string PNU_LOTE_OU_SERIE,
                                                string PNU_REPARAVEL,
                                                string PNU_ESTOCAVEL,
                                                string PNU_CONTROLA_VIDA,
                                                string PNU_AERONAUTICO,
                                                string PNU_IMPORTADO,
                                                string PNU_INSUMO,
                                                string UME_CODIGO_PESO,
                                                string PNU_PESO,
                                                string NCM_CODIGO,
                                                string PNU_PASTA_MANUAL,
                                                string PNU_OBSERVACOES,
                                                string USU_INSERT,
                                                string DATA_INSERT,
                                                string USU_UPDATE,
                                                string DATA_UPDATE,
                                                string PNU_POSSUI_LE,
                                                string PNU_CALIBRAVEL,
                                                string PNU_PATRIMONIO,
                                                string PNU_CLASSE,
                                                string PNU_FABRICACAO,
                                                string PNU_EQPOBRIG_DT_FABR,
                                                string PNU_EQPOBRIG_DT_INSTAL,
                                                string PNU_EQPALTERA_PN,
                                                string PNU_EQPALTERA_SN
                                                )
        {

            string sql = " UPDATE PN_CADASTRO SET " +
                         //"      PART_NUMBER_ID                  = " + PART_NUMBER_ID + ", " +
                         "      PNU_PART_NUMBER                 = " + Util.retonarAspas(PNU_PART_NUMBER, true) + ", " +
                         "      PNU_DESCRICAO_PORTUGUES         = " + Util.retonarAspas(PNU_DESCRICAO_PORTUGUES, true) + ", " +
                         "      PNU_DESCRICAO_INGLES            = " + Util.retonarAspas(PNU_DESCRICAO_INGLES, true) + ", " +
                         "      PNU_ATIVO                       = " + Util.retonarAspas(PNU_ATIVO, true) + ", " +
                         "      FABRICANTE_ID                   = " + Util.retonarNull(FABRICANTE_ID) + ", " +
                         //"      UME_CODIGO                      = " + Util.retonarAspas(UME_CODIGO, true) + ", " +
                         //"      PNU_LOTE_OU_SERIE               = " + Util.retonarAspas(PNU_LOTE_OU_SERIE, true) + ", " +
                         //"      PNU_REPARAVEL                   = " + Util.retonarAspas(PNU_REPARAVEL, true) + ", " +
                         //"      PNU_ESTOCAVEL                   = " + Util.retonarAspas(PNU_ESTOCAVEL, true) + ", " +
                         //"      PNU_CONTROLA_VIDA               = " + Util.retonarAspas(PNU_CONTROLA_VIDA, true) + ", " +
                         //"      PNU_AERONAUTICO                 = " + Util.retonarAspas(PNU_AERONAUTICO, true) + ", " +
                         "      PNU_IMPORTADO                   = " + Util.retonarAspas(PNU_IMPORTADO, true) + ", " +
                         "      PNU_INSUMO                      = " + Util.retonarAspas(PNU_INSUMO, true) + ", " +
                         //"      UME_CODIGO_PESO                 = " + Util.retonarAspas(UME_CODIGO_PESO, true) + ", " +
                         //"      PNU_PESO                        = " + PNU_PESO + ", " +
                         //"      NCM_CODIGO                      = " + Util.retonarAspas(NCM_CODIGO, true) + ", " +
                         //"      PNU_PASTA_MANUAL                = " + Util.retonarAspas(PNU_PASTA_MANUAL, true) + ", " +
                         "      PNU_OBSERVACOES                 = " + Util.retonarAspas(PNU_OBSERVACOES, true) + ", " +
                         //"      USU_INSERT                      = " + USU_INSERT + ", " +
                         //"      DATA_INSERT                     = " + DATA_INSERT + ", " +
                         "      USU_UPDATE                      = " + Util.retonarAspas(USU_UPDATE, true) + ", " +
                         "      DATA_UPDATE                     = " + Util.retonarAspas(DATA_UPDATE, true) + ", " +
                         //"      PNU_POSSUI_LE                   = " + Util.retonarAspas(PNU_POSSUI_LE, true) + ", " +
                         //"      PNU_CALIBRAVEL                  = " + Util.retonarAspas(PNU_CALIBRAVEL, true) + ", " +
                         //"      PNU_PATRIMONIO                  = " + Util.retonarAspas(PNU_PATRIMONIO, true) + ", " +
                         "      PNU_CLASSE                      = " + Util.retonarAspas(PNU_CLASSE, true) + ", " +
                         //"      PNU_FABRICACAO                  = " + Util.retonarAspas(PNU_FABRICACAO, true) +
                         "      PNU_EQPOBRIG_DT_FABR            = " + Util.retonarAspas(PNU_EQPOBRIG_DT_FABR, true) + ", " +
                         "      PNU_EQPOBRIG_DT_INSTAL          = " + Util.retonarAspas(PNU_EQPOBRIG_DT_INSTAL, true) + ", " +
                         "      PNU_EQPALTERA_PN                = " + Util.retonarAspas(PNU_EQPALTERA_PN, true) + ", " +
                         "      PNU_EQPALTERA_SN                = " + Util.retonarAspas(PNU_EQPALTERA_SN, true) + " " +
                         " WHERE PART_NUMBER_ID =  " + PART_NUMBER_ID;
            try
            {
                fireBird._ExecutarComandoRetornandoID(sql, conectionString, false, usuario);
            }
            catch
            { }
        }



        public void _excluir_PartNumber(string PART_NUMBER_ID)
        {
            string sql = "DELETE FROM PN_CADASTRO WHERE PART_NUMBER_ID = " + PART_NUMBER_ID;
            try
            {
                fireBird._ExecutarComandoRetornandoID(sql, conectionString, false, usuario);
            }
            catch
            { }
        }



        #endregion
    }
}
